﻿'========================================================================
'功能:群組授權管理頁面
'作者:andy
'日期: 2011/09/08
'========================================================================

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Partial Class WebForm_Manage_GroupRights
    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = UID
            hiActulaUID.Value = ActualUID
            hiDBName.Value = dbName
            If Not ChkProgramRight(1) Then '查詢
                gvMenu.Visible = False
            End If
            If Not ChkProgramRight(2) Then '設定
                gvMenu.Enabled = False

            End If
            'If Not ChkProgramRight(3) Then '修改權限
            '    gvMenu.Enabled = False

            'End If
            lblTitle.Text = GetLocalResourceObject("lblTitle")
            ''取得群組代碼選項
            Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
            Dim dtGroup As DataTable = groupBBL.GetGroupIDdt(dbName)
            ddlGroupID.DataSource = dtGroup
            ddlGroupID.DataBind()



            For ii As Integer = 2 To 21
                gvMenu.Columns(ii).Visible = True
            Next

            Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
            Dim max As Integer = bbl.GetMenuByRootNameUIDMaxCol("", UID, hiDBName.Value)
            For jj As Integer = max + 2 To 21
                gvMenu.Columns(jj).Visible = False
            Next

        End If

    End Sub

    
    Protected Sub gvMenu_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenu.RowCommand
        '設定按鈕
        'If e.CommandName = "Select" Then
        '    If gvMenu.SelectedIndex > -1 Then '有選定時才可以動作
        '        lblMenuName.Text = gvMenu.Rows(gvMenu.SelectedIndex).Cells(1).Text '設定右方的頁面名稱內容
        '        gvGroupRights.Visible = True '查出某一頁面的功能鍵資料
        '        gvGroupRights.DataBind()
        '    Else
        '        lblMenuName.Text = ""
        '        gvGroupRights.Visible = False
        '    End If
        'End If

    End Sub

    Protected Sub gvMenu_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMenu.SelectedIndexChanged
        If gvMenu.SelectedIndex > -1 Then '有選定時才可以動作
            'lblMenuName.Text = gvMenu.Rows(gvMenu.SelectedIndex).Cells(1).Text '設定右方的頁面名稱內容
            'gvGroupRights.Visible = True '查出某一頁面的功能鍵資料
            'gvGroupRights.DataBind()
        Else
           
        End If

    End Sub

    ''' <summary>
    ''' 換頁次時要取消選定的動作
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>換頁次時要取消選定的動作</remarks>
    Protected Sub gvMenu_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvMenu.PageIndexChanged
        gvMenu.SelectedIndex = -1
      

    End Sub

    Protected Sub ddlGroupID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlGroupID.SelectedIndexChanged
        For ii As Integer = 2 To 21
            gvMenu.Columns(ii).Visible = True
        Next

        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        Dim max As Integer = bbl.GetMenuByRootNameUIDMaxCol(ddlRootName.SelectedValue, UID, hiDBName.Value)
        For jj As Integer = max + 2 To 21
            gvMenu.Columns(jj).Visible = False
        Next

    End Sub

    
    
    Protected Sub cbUseRight_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        'Dim ProgramID As Integer = Integer.Parse(gvMenu.SelectedValue)
        'Dim SeqNo As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        'Dim UseRight = CType(sender, CheckBox).Checked
        'groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        'gvGroupRights.DataBind()
    End Sub

    
    
    Protected Sub ddlRootName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRootName.SelectedIndexChanged
        For ii As Integer = 2 To 21
            gvMenu.Columns(ii).Visible = True
        Next

        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        Dim max As Integer = bbl.GetMenuByRootNameUIDMaxCol(ddlRootName.SelectedValue, UID, hiDBName.Value)
        For jj As Integer = max + 2 To 21
            gvMenu.Columns(jj).Visible = False
        Next
    End Sub

    Protected Sub cb01_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 1
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb02_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 2
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub

    Protected Sub cb03_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 3
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb04_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 4
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb05_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 5
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb06_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 6
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb07_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 7
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb08_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 8
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb09_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 9
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub

    Protected Sub cb10_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 10
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb11_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 11
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb12_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 12
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb13_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 13
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb14_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 14
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb15_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 15
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb16_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 16
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb17_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 17
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb18_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 18
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb19_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 19
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
    Protected Sub cb20_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        Dim ProgramID As Integer = Integer.Parse(CType(sender, CheckBox).ToolTip)
        Dim SeqNo As Integer = 20
        Dim UseRight = CType(sender, CheckBox).Checked
        groupBBL.UpdateRight(ddlGroupID.SelectedValue, ProgramID, SeqNo, UseRight, hiActulaUID.Value, dbName)
        gvMenu.DataBind()
    End Sub
End Class
